package com.ifonly.common.ztree.simple;

import java.io.Serializable;

/**
 * <p>
 * . 简单 JSON 数据
 * ZTree ZNode 封装
 * </p>
 *
 * @author ifonly
 * @version 1.0 2016-01-19 19:55
 * @since JDK 1.6
 */
public class SimpleZNode<ID, E> implements Serializable {
    private static final long serialVersionUID = -1556549910232744977L;

    /**
     * 主键
     */
    private ID id;
    /**
     * 父主键
     */
    private ID pid;
    /**
     * 节点名称
     */
    private String name;
    /**
     * 是否open
     */
    private boolean open;
    /**
     * 是否为parent节点
     */
    private boolean isParent;
    /**
     * 节点是否选择
     */
    boolean checked;

    /**
     * 节点对应的原始数据
     */
    private E original;

    public SimpleZNode() {
    }

    public SimpleZNode(ID id, ID pid, String name, E original) {
        this.id = id;
        this.pid = pid;
        this.name = name;
        this.original = original;
    }

    public ID getId() {
        return id;
    }

    public void setId(ID id) {
        this.id = id;
    }

    public ID getPid() {
        return pid;
    }

    public void setPid(ID pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    public boolean isParent() {
        return isParent;
    }

    public void setIsParent(boolean isParent) {
        this.isParent = isParent;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public SimpleZNode(E original) {
        this.original = original;
    }

    /**
     * 创建 Simple zNode 对象
     *
     * @param id ID
     * @param pid 上级ID
     * @param name 名称
     * @param original 原始数据
     * @param <ID> 上级ID类型
     * @param <E> 原始数据类型
     * @return SimpleZNode 对象
     */
    public static <ID, E> SimpleZNode<ID, E> create(ID id, ID pid, String name, E original) {
        SimpleZNode<ID, E> zNode = new SimpleZNode<ID, E>(id, pid, name, original);
        zNode.setOpen(true);
        return zNode;
    }

}
